//
//  RandomArray.m
//  Mahjong
//
//  Created by 饶首建 on 17/6/27.
//  Copyright © 2017年 com.ikamobile.com. All rights reserved.
//

#import "RandomArray.h"
#import "UserKeyChain.h"

@implementation RandomArray

+ (NSString *)idfaString{
    NSString * strUUID = (NSString *)[UserKeyChain load:KEY_CUSTOMEID];
    if (strUUID.length) {
        return strUUID;
    }else{
        strUUID = [self random:8];
        [UserKeyChain save:KEY_CUSTOMEID data:strUUID];
        return strUUID;
    }
}

+(NSString *)random:(NSInteger)length{
    //随机数从这里边产生
    NSString *str = @"0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";
    NSMutableArray *startArray = [NSMutableArray arrayWithArray:[str componentsSeparatedByString:@","]];
    //随机数产生结果
    NSMutableArray *resultArray=[[NSMutableArray alloc] initWithCapacity:0];
    //随机数个数
    NSInteger m = MAX(length, 8);
    for (int i=0; i<m; i++) {
        int t=arc4random()%startArray.count;
        resultArray[i]=startArray[t];
        startArray[t]=[startArray lastObject]; //为更好的乱序，故交换下位置
        [startArray removeLastObject];
    }
    return [resultArray componentsJoinedByString:@""];
}

@end
